using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using DIS_DAL_WS.Models;

namespace DIS_DAL_WS.DTO
{
    [DataContract]
	public class RoleFunctionsDTO
	{
        [DataMember]
		public int ID { get; set; }
        [DataMember]
		public int IDRole { get; set; }
        [DataMember]
		public int IDFunction { get; set; }
        [DataMember]
        public RoleDTO Role { get; set; }
        [DataMember]
        public FunctionsDTO Function { get; set; }

        public static RoleFunctionsDTO Translate(RoleFunctions Entity)
        {
            if (Entity != null)
            {
                var dto = new RoleFunctionsDTO
                {
                    ID = Entity.ID,
                    Role = RoleDTO.TranslateBase(Entity.Role),
                    Function = FunctionsDTO.Translate(Entity.Functions)
                };
                if (Entity.IDRole != null)
                {
                    dto.IDRole = Entity.IDRole.Value;
                }
                else
                {
                    dto.IDRole = -1;
                }
                if (Entity.IDFunction != null)
                {
                    dto.IDFunction = Entity.IDFunction.Value;
                }
                else
                {
                    dto.IDFunction = -1;
                }
                return dto;
            }
            return null;
        }

        public static RoleFunctions Reverse(RoleFunctionsDTO obj)
        {
            var entity = new RoleFunctions
            {
                ID = obj.ID
            };
            if (obj.IDRole != -1)
            {
                entity.IDRole = obj.IDRole;
            }
            if (obj.IDFunction != -1)
            {
                entity.IDFunction = obj.IDFunction;
            }
            return entity;
        }

        public void UpdateEntity(ref RoleFunctions entity)
        {
            if (IDRole != -1)
            {
                entity.IDRole = IDRole;
            }
            if (IDFunction != -1)
            {
                entity.IDFunction = IDFunction;
            }
        }
	}
}